<?php 
use Wdl\helper\sendHelper;
use Wdl\helper\webHelper;

defined('IN_IA') or exit('Access Denied');
global $_GPC, $_W;
load()->func('tpl'); 
$uniacid = webHelper::bindUniacid(); 
$openid = $_W['openid'];
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'sechouse';	


$rd = !empty($_GPC['rd']) ? $_GPC['rd'] : 'index';


$sec = webHelper::fetch_place_data('setting', 'display');
$selects = $this->_forms;
$selects['areas'] =  $sec['areas'];
//区域下拉选择
if($operation == 'cityareas'){
    $id = $_GPC['id'];    
    $filename = 'data[area]';
    if(!empty( $_GPC['filename'])){
         $filename = $_GPC['filename'];
    }    
    echo  form_element::select($selects['areas'], $filename ,'area' );
    exit;
    //新增商圈
}elseif($operation == 'savequan'){
    sendHelper::add_quan_data();
    echo json_encode( webHelper::quans());
    exit;
}
$id = intval($_GPC['id']);
if($id){
        
    $item = sendHelper::get_house_item($id);
    $loupan = sendHelper::get_loupan_item($id); //楼盘数据
    
    if(empty($item)){
        message('找不到房源数据', $this->createWebUrl('send', ['op'=>$operation ]) , 'error');
    }
    //编辑房源的时候得到类型；
    $operation = webHelper::zhutype_map_type($item['zhutype']);
}
//处理提交保存房源
if(checksubmit('submit')){
    
    $id = sendHelper::send_post( $id ); 
    if($_GPC['backway'] == 1)
       $return_url = $this->createWebUrl('send', ['op'=>$operation, 'id'=> $id]);
    elseif($_GPC['backway'] == 2)
       $return_url = $this->createWebUrl('send', ['op'=>$operation ]);
    else
       $return_url = $this->createWebUrl('sendlist', ['op'=>$operation ]);
  
    message('操作成功！', $return_url, 'success');
}

$rsbrokers = pdo_fetchall("select * from ".tablename("kbwdl_broker")." where uniacid=:uniacid and iscompany=1 and disabled=0",['uniacid'=>$uniacid]);
foreach($rsbrokers as $b){
    $brokers[$b['id']] = $b['truename'] ."-".$b['mobile'];
}
 
$citys = webHelper::citys();

$selects['quan'] = webHelper::quans();
//默认城市设置1
 
$item['city_id'] = 1;
 /**
  * zhutype:0=二手房 1=写字楼 3=新房 4=商铺 7=厂房 8=仓库
  */
$submenus =  webHelper::house_type();
//房源的类型
$zhutype = isset($submenus[$operation]['zhutype']) ? $submenus[$operation]['zhutype'] :0;
$renttype = isset($submenus[$operation]['rent_type']) ? $submenus[$operation]['rent_type'] :0;
if(isset($item['rent_type'])){ $renttype = $item['rent_type']; }//编辑的时候 
if(isset($_GPC['renttype'])) {
    //默认出售 2=出租 3=转让
    $renttype = $_GPC['renttype'];
}
$template_name = sprintf("send/%s",  $operation);

include $this->template('send/index');